package com.lch;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/user", "root", "fdjr34");

        Statement stat = conn.createStatement();

//        insert(stat);
        select(stat);


        stat.close();
        conn.close();
    }

    private static void select(Statement stat) throws SQLException {

        String sql = "select * from user;";
        ResultSet rs = stat.executeQuery(sql);


        while (rs.next()) {

            System.out.println(rs.getString("name") + "\t" + rs.getString("password"));
        }
    }

    private static void insert(Statement stat) throws SQLException {
        String sql = "insert into user(`name`, password) values(\"lch\", \"123\");";
        int row = stat.executeUpdate(sql);
        System.out.println(row);
    }
}
